//
//  UITabBarItem+Extension.swift
//  Sina15
//
//  Created by 盼 on 16/4/8.
//  Copyright © 2016年 pan. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(imageName: String? = nil,title: String? = nil,target: AnyObject?,action: Selector) {
        
        self.init()
        
        let btn = UIButton()
        
        //设置图片
        if let img = imageName {
            btn.setImage(UIImage(named: img), forState: .Normal)
            btn.setImage(UIImage(named: img+"_highlighted"), forState: .Highlighted)
        }

        //设置title
        btn.setTitle(title, forState: .Normal)
        
        //设置字体大小和颜色
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        //给按钮设置frame
        btn.sizeToFit()
        
        //给按钮添加点击事件
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        customView = btn;

    }
    
}

